package org.jeecgframework.core.util.clean;

import jeecg.business.entity.site.SiteEntity;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.PrettyXmlSerializer;
import org.htmlcleaner.TagNode;
import org.jeecgframework.core.util.DataUtils;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.clean.bean.HtmlParseResult;
import org.jeecgframework.core.util.code.CodeUtil;
import org.jeecgframework.core.util.http.HttpClientUtil;

public class DongfangCaiwuHtmlCleanUtil {
	
	
	public static HtmlParseResult fetchDongfangcaiwu4Html(String html , String charset,SiteEntity site , String cookies){
		HtmlParseResult result = null;
		try{
			result = new HtmlParseResult();
			
			html = html.substring(html.indexOf("jsondata = ")+"jsondata = ".length());
			html = html.substring(0,html.length()-1);
			
			JSONObject jobj = JSONObject.fromObject(html);
			JSONArray dataResult = jobj.getJSONArray("DataResult");
			JSONObject data = null;
			if(dataResult != null){
				String url = null;
				HtmlParseResult each = null;
				for(int i=0;i<dataResult.size();i++){
					data = dataResult.getJSONObject(i);
					url = data.getString("Url");
					each = new HtmlParseResult();
		            each.setType(site.getJclx());
		            each.setUrl(url);
		            result.addChildResult(each);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		return result;
	}
	
	public static HtmlParseResult fetchSinaBlog(String url ,String charset,SiteEntity site , String cookies){
		String str = HttpClientUtil.getSourceFromUrl(url, site.getWyzfj(), cookies);
		return fetchDongfangcaiwu4Html(str, charset, site, cookies);
	}
}
